package com.xiaohong.goods.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * Swagger配置
 */
@Configuration
public class SwaggerConfig {
// swagger3+OpenAPI3

    @Bean
    public GroupedOpenApi userApi() {
        return GroupedOpenApi.builder()
                .group("brand")
                .pathsToMatch("/brand/**")
                .build();
    }
    @Bean
    public GroupedOpenApi SpuApi() {
        return GroupedOpenApi.builder()
                .group("spu")
                .pathsToMatch("/spu/**")
                .build();
    }
    @Bean
    public GroupedOpenApi CategoryApi() {
        return GroupedOpenApi.builder()
                .group("category")
                .pathsToMatch("/category/**")
                .build();
    }
    @Bean
    public GroupedOpenApi SpecGroupApi() {
        return GroupedOpenApi.builder()
                .group("specGroup")
                .pathsToMatch("/specGroup/**")
                .build();
    }
    @Bean
    public GroupedOpenApi SpecParamApi() {
        return GroupedOpenApi.builder()
                .group("specParam")
                .pathsToMatch("/specParam/**")
                .build();
    }
    @Bean
    public GroupedOpenApi SkuApi() {
        return GroupedOpenApi.builder()
                .group("sku")
                .pathsToMatch("/sku/**")
                .build();
    }


    @Bean
    public OpenAPI springShopOpenAPI() {
        SecurityRequirement securityRequirement = new SecurityRequirement().addList("Authorization"); // 名字和创建的SecuritySchemes一致
        List<SecurityRequirement> list = new ArrayList<>();
        list.add(securityRequirement);
        return new OpenAPI()
                .components(new Components().addSecuritySchemes("Authorization", // key值
                        new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY) //请求认证类型
                                .name("Authorization") //API key参数名
                                .description("token令牌") //API key描述
                                .in(SecurityScheme.In.HEADER))) //设置API key的存放位置
                .security(list)
                .info(new Info().title("商品微服务")
                        .description("商品微服务接口文档")
                        .version("v0.0.1")
                        .license(new License().name("小鸿").url("http://www.xiaohong.work")));
    }




}
